package com.localjoycommunity.cpdj.project.system.controller;

import java.util.List;

import com.localjoycommunity.cpdj.project.system.domain.vo.UserCourseWatchVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.localjoycommunity.cpdj.framework.aspectj.lang.annotation.Log;
import com.localjoycommunity.cpdj.framework.aspectj.lang.enums.BusinessType;
import com.localjoycommunity.cpdj.project.system.domain.UserCourseWatch;
import com.localjoycommunity.cpdj.project.system.service.IUserCourseWatchService;
import com.localjoycommunity.cpdj.framework.web.controller.BaseController;
import com.localjoycommunity.cpdj.framework.web.domain.AjaxResult;
import com.localjoycommunity.cpdj.common.utils.poi.ExcelUtil;
import com.localjoycommunity.cpdj.framework.web.page.TableDataInfo;

/**
 * 用户学习记录Controller
 *
 * @author leepandar
 * @date 2020-12-16
 */
@RestController
@RequestMapping("/system/watch")
public class UserCourseWatchController extends BaseController {
    @Autowired
    private IUserCourseWatchService userCourseWatchService;

    /**
     * 用户学习历史
     */
    @GetMapping("/list")
    public TableDataInfo list(UserCourseWatchVo userCourseWatchVo) {
        startPage();
        List<UserCourseWatchVo> list = userCourseWatchService.selectUserCourseWatchListHistory(userCourseWatchVo);
        return getDataTable(list);
    }

    /**
     * 用户学习记录
     */
    @GetMapping("/record/list")
    public TableDataInfo recordList(UserCourseWatch userCourseWatch) {
        startPage();
        List<UserCourseWatch> list = userCourseWatchService.selectUserCourseWatchList(userCourseWatch);
        return getDataTable(list);
    }

    /**
     * 导出用户学习历史
     */
    @Log(title = "用户学习历史", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserCourseWatchVo userCourseWatchVo) {
        List<UserCourseWatchVo> list = userCourseWatchService.selectUserCourseWatchListHistory(userCourseWatchVo);
        ExcelUtil<UserCourseWatchVo> util = new ExcelUtil<UserCourseWatchVo>(UserCourseWatchVo.class);
        return util.exportExcel(list, "用户学习历史");
    }
    /**
     * 导出用户学习记录
     */
    @Log(title = "用户学习历史", businessType = BusinessType.EXPORT)
    @GetMapping("/export/record")
    public AjaxResult exportRecord(UserCourseWatch userCourseWatch) {
        List<UserCourseWatch> list = userCourseWatchService.selectUserCourseWatchList(userCourseWatch);
        ExcelUtil<UserCourseWatch> util = new ExcelUtil<UserCourseWatch>(UserCourseWatch.class);
        return util.exportExcel(list, "用户学习记录");
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(userCourseWatchService.selectUserCourseWatchById(id));
    }

    /**
     * 新增
     */
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCourseWatch userCourseWatch) {
        return toAjax(userCourseWatchService.insertUserCourseWatch(userCourseWatch));
    }

    /**
     * 修改
     */
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCourseWatch userCourseWatch) {
        return toAjax(userCourseWatchService.updateUserCourseWatch(userCourseWatch));
    }

    /**
     * 删除
     */
    @Log(title = "", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userCourseWatchService.deleteUserCourseWatchByIds(ids));
    }
}
